package com.ymttest.business.service;

import java.io.IOException;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.auth.parameter.SignAuthBean;
import com.ymatou.iapi.auth.service.SignAuthCall;
import com.ymatou.iapi.login.parameter.AliUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindAliUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindBean;
import com.ymatou.iapi.login.parameter.BindSinaWeiboUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.BindWeiXinUseroRequestDtoBean;
import com.ymatou.iapi.login.parameter.LoginAuthBean;
import com.ymatou.iapi.login.parameter.ThirdpartyLoginBean;
import com.ymatou.iapi.login.parameter.SinaWeiBoUserRequestDtoBean;
import com.ymatou.iapi.login.parameter.UnBindThirdPartyAccountDtoBean;
import com.ymatou.iapi.login.parameter.WxUserLoginBean;
import com.ymatou.iapi.login.service.AliUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindAliUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindCall;
import com.ymatou.iapi.login.service.BindSinaWeiboUserRequestDtoCall;
import com.ymatou.iapi.login.service.BindWeiXinUseroRequestDtoCall;
import com.ymatou.iapi.login.service.LoginAuthCall;
import com.ymatou.iapi.login.service.ThirdpartyLoginCall;
import com.ymatou.iapi.login.service.SinaWeiBoUserRequestDtoCall;
import com.ymatou.iapi.login.service.UnBindThirdPartyAccountDtoCall;
import com.ymatou.iapi.login.service.WeiXinUserRequestDtoCall;
import com.ymatou.iapi.login.service.WxUserLoginCall;
import com.ymatou.iapi.selleraccount.parameter.GetSellerBaseInfoBean;
import com.ymatou.iapi.selleraccount.parameter.SellerBaseInfo;
import com.ymatou.iapi.selleraccount.service.GetSellerBaseInfoCall;
import com.ymatou.iapi.selleronline.parameter.OnlinestatusOpBean;
import com.ymatou.iapi.selleronline.service.OnlinestatusOpCall;
import com.ymatou.iapi.userregister.parameter.SellerRegisterBean;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.SellerRegisterCall;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.AddressRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.BatchUserBriefInfoByLoginIdBean;
import com.ymatou.iapi.userservice.parameter.BatchUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.BindEmailBean;
import com.ymatou.iapi.userservice.parameter.CheckMobileCanBindThirdPartyUserDtoBean;
import com.ymatou.iapi.userservice.parameter.CheckThirdPartyUserIsRealNeedBindMobileDtoBean;
import com.ymatou.iapi.userservice.parameter.CloseAccountBean;
import com.ymatou.iapi.userservice.parameter.ExpChangeBean;
import com.ymatou.iapi.userservice.parameter.LockUserRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.MobileexistsBean;
import com.ymatou.iapi.userservice.parameter.PasswordResetRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.SetIdcardBean;
import com.ymatou.iapi.userservice.parameter.SetNickNameDtoBean;
import com.ymatou.iapi.userservice.parameter.SetRemarkBean;
import com.ymatou.iapi.userservice.parameter.SingleWeiXinBriefInfoBean;
import com.ymatou.iapi.userservice.parameter.UnBindMailBean;
import com.ymatou.iapi.userservice.parameter.UnBindMobileRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.UpdateTradingPwdBean;
import com.ymatou.iapi.userservice.parameter.UpdateWxHeadImgBean;
import com.ymatou.iapi.userservice.parameter.enums.AppSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ChannelSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.GenderEnum;
import com.ymatou.iapi.userservice.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.userservice.parameter.enums.ThirdPartyTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.UserTypeEnum;
import com.ymatou.iapi.userservice.parameter.enums.VisitLanguageEnum;
import com.ymatou.iapi.userservice.parameter.req.BindMobileReq;
import com.ymatou.iapi.userservice.parameter.req.BindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.parameter.req.SetUserLogoReq;
import com.ymatou.iapi.userservice.parameter.req.UnBindThirdPartyUserReq;
import com.ymatou.iapi.userservice.parameter.resp.AddressResp;
import com.ymatou.iapi.userservice.parameter.resp.UserInfo2;
import com.ymatou.iapi.userservice.service.AddressRequestDtoCall;
import com.ymatou.iapi.userservice.service.BatchUserBriefInfoByLoginIdCall;
import com.ymatou.iapi.userservice.service.BatchUserRequestDtoCall;
import com.ymatou.iapi.userservice.service.BindEmailCall;
import com.ymatou.iapi.userservice.service.BindMobileCall;
import com.ymatou.iapi.userservice.service.BindThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.CheckMobileCanBindThirdPartyUserDtoCall;
import com.ymatou.iapi.userservice.service.CheckThirdPartyUserIsRealNeedBindMobileDtoCall;
import com.ymatou.iapi.userservice.service.CloseAccountCall;
import com.ymatou.iapi.userservice.service.CreateThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.ExpChangeCall;
import com.ymatou.iapi.userservice.service.GAddressRequestDtoCall;
import com.ymatou.iapi.userservice.service.LockUserRequestDtoCall;
import com.ymatou.iapi.userservice.service.MobileexistsCall;
import com.ymatou.iapi.userservice.service.PasswordResetRequestDtoCall;
import com.ymatou.iapi.userservice.service.SetIdcardCall;
import com.ymatou.iapi.userservice.service.SetNickNameDtoCall;
import com.ymatou.iapi.userservice.service.SetRemarkCall;
import com.ymatou.iapi.userservice.service.SetUserLogoCall;
import com.ymatou.iapi.userservice.service.SingleWeiXinBriefInfoCall;
import com.ymatou.iapi.userservice.service.UnBindMailCall;
import com.ymatou.iapi.userservice.service.UnBindMobileRequestDtoCall;
import com.ymatou.iapi.userservice.service.UnBindThirdPartyUserCall;
import com.ymatou.iapi.userservice.service.UnLockUserRequestDtoCall;
import com.ymatou.iapi.userservice.service.UpdateTradingPwdCall;
import com.ymatou.iapi.userservice.service.UpdateWxHeadImgCall;
import com.ymt.core.tool.Logger;
import com.ymt.core.tool.RSAUtils;
import com.ymttest.common.enums.UserTerminalSourceEnum;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.UserSafeWapper;
import com.ymttest.utils.DesUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.AppTypeChannel;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;

public class JUserCallService {
	/**
	 * 默认头像
	 */
	public static String oldDefaultImg = "http://img.ymatou.com/portal/images/default.png";
	public static String defaultImg = "http://staticontent.ymatou.com/app/userlogo/mj.jpg";
	public static String defaultSellerImg = "http://staticontent.ymatou.com/app/userlogo/ms.jpg";
	public static String defaultLoginPwd = "123456aB";
	public static String uLoginPwd = "Abc12345";
	public static String EncryptKey = "_ymt2018_";
	public static Boolean OpenEncrypt = true;
	/**
	 * 查询商家信息
	 * @param sellerid
	 * @return 
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SellerBaseInfo getSellerInfo(Integer sellerid) throws ClientProtocolException, IOException {
		GetSellerBaseInfoBean GetSellerBaseInfoBean=new GetSellerBaseInfoBean();
		GetSellerBaseInfoCall GetSellerBaseInfoCall=new GetSellerBaseInfoCall();
		GetSellerBaseInfoBean.setUserId(sellerid);
		GetSellerBaseInfoCall.setData(GetSellerBaseInfoBean);
		GetSellerBaseInfoCall.callService();
		return GetSellerBaseInfoCall.getSellerBaseInfo();
	}
	/**
	 * 检查第三方账号是否要绑定手机 有绑定过返回no 没绑定过返回yes
	 * @param thirdpartyid
	 * @param ThirdPartyType
	 * @return yes or no
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static String CheckThirdPartyUserIsRealNeedBindMobile(String thirdpartyid, String ThirdPartyType) throws ClientProtocolException, IOException {
		CheckThirdPartyUserIsRealNeedBindMobileDtoBean checkthirdpartyuserisrealneedbindmobiledtoBean = new CheckThirdPartyUserIsRealNeedBindMobileDtoBean();
		CheckThirdPartyUserIsRealNeedBindMobileDtoCall checkthirdpartyuserisrealneedbindmobiledtoCall = new CheckThirdPartyUserIsRealNeedBindMobileDtoCall();
		checkthirdpartyuserisrealneedbindmobiledtoBean.setThirdPartyId(thirdpartyid);
		checkthirdpartyuserisrealneedbindmobiledtoBean.setThirdPartyType(ThirdPartyType);
		checkthirdpartyuserisrealneedbindmobiledtoCall.setData(checkthirdpartyuserisrealneedbindmobiledtoBean);
		checkthirdpartyuserisrealneedbindmobiledtoCall.callService();
		return checkthirdpartyuserisrealneedbindmobiledtoCall.getString("Result");
	}

	/**
	 * 码头用户微信信息
	 * 
	 * @param userId
	 * @param businessType
	 * @return Logger.debug(result.get("UserId").getAsInt());<br/>
	 *         Logger.debug( result.get("LoginId").getAsString());<br/>
	 *         Logger.debug( result.get("WeiXinNickName").getAsString());<br/>
	 *         Logger.debug(result.get("LogoUrl").getAsString());<br/>
	 *         Logger.debug(result.get("WeiXinLogoUrl").getAsString());<br/>
	 * 
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static JsonObject SingleWeiXinBriefInfoCall(Integer userId, Integer businessType) throws ClientProtocolException, IOException {
		SingleWeiXinBriefInfoBean SingleWeiXinBriefInfoBean = new SingleWeiXinBriefInfoBean();
		SingleWeiXinBriefInfoCall SingleWeiXinBriefInfoCall = new SingleWeiXinBriefInfoCall();
		SingleWeiXinBriefInfoBean.setUserId(userId);
		SingleWeiXinBriefInfoBean.setBusinessType(businessType);
		SingleWeiXinBriefInfoCall.setData(SingleWeiXinBriefInfoBean);
		SingleWeiXinBriefInfoCall.callService();
		JsonObject result = SingleWeiXinBriefInfoCall.getJsonObject().get("Result").getAsJsonObject();

		return result;
	}

	/**
	 * 设置昵称(登入id)，只能修改一次
	 * 
	 * @param UserId
	 * @param NickName
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void resetNickName(int UserId, String NickName) throws ClientProtocolException, IOException {
		Logger.comment("设置昵称uid:" + UserId + "：昵称:" + NickName);
		SetNickNameDtoBean setnicknamedtoBean = new SetNickNameDtoBean();
		SetNickNameDtoCall setnicknamedtoCall = new SetNickNameDtoCall();
		setnicknamedtoBean.setNickName(NickName);
		setnicknamedtoBean.setUserId(UserId);
		setnicknamedtoCall.setData(false, setnicknamedtoBean);
		setnicknamedtoCall.callService();
	}

	/**
	 * 获取用户头像
	 * 
	 * @param uid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static String GetLogoUrl(Integer uid) throws ClientProtocolException, IOException {
		BatchUserBriefInfoByLoginIdCall batchuserbriefinfobyloginidCall = new BatchUserBriefInfoByLoginIdCall();
		BatchUserBriefInfoByLoginIdBean batchuserbriefinfobyloginidBean = new BatchUserBriefInfoByLoginIdBean();
		String loginid = GetUserInfo(uid).getLoginId();
		List<String> LoginIdList = new ArrayList<>();
		LoginIdList.add(loginid);
		batchuserbriefinfobyloginidBean.setLoginIdList(LoginIdList);
		batchuserbriefinfobyloginidCall.setData(batchuserbriefinfobyloginidBean);
		batchuserbriefinfobyloginidCall.callService();
		JsonArray Result = batchuserbriefinfobyloginidCall.getJsonObject().get("Result").getAsJsonArray();
		String logoUrl = Result.get(0).getAsJsonObject().get("LogoUrl").getAsString();
		return logoUrl;
	}

	/**
	 * 注销用户
	 * 
	 * @param uid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static CloseAccountCall CloseAccount(Integer uid) throws ClientProtocolException, IOException {
		CloseAccountBean closeaccountBean = new CloseAccountBean();
		CloseAccountCall closeaccountCall = new CloseAccountCall();
		closeaccountBean.setUserId(uid);
		closeaccountBean.setReason("testClose");
		closeaccountCall.setData(closeaccountBean);
		closeaccountCall.callService();
		return closeaccountCall;
	}

	/**
	 * 默认初始化创建用户bean
	 * 
	 * @param cur
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static CreateUserReq initCreateUserBean(CreateUserReq cur) throws ClientProtocolException, IOException {
		if (cur == null) {
			cur = new CreateUserReq();
		}
		cur.setAppId("autotest");
		cur.setChannelSource(ChannelSourceEnum.Other);
		cur.setClientIp(TestDataManager.getRandomIp());
		cur.setDeviceId(TestDataManager.getRandomUUID().toString());
		cur.setEquimentid(TestDataManager.getRandomUUID().toString());
		cur.setLoginId("NewJavaReg_" + TestDataManager.getRandomNum(10));
		cur.setLoginPassword(JUserCallService.defaultLoginPwd);
		cur.setMail(TestDataManager.getEmail());

		String moblie = TestDataManager.getPhoneNum();
		if (mobileExists(moblie)) {
			moblie = TestDataManager.getPhoneNum();
		}
		cur.setMobile(moblie);
		cur.setRegSource(AppSourceEnum.App);
		cur.setRequestId(TestDataManager.getRandomUUID().toString());
		cur.setTerminalSource(TerminalSourceEnum.IOS);
		cur.setUserType(UserTypeEnum.Normal);
		cur.setVisitLanguage(VisitLanguageEnum.Chinese);
		return cur;
	}

	/**
	 * 获取用户信息
	 * 
	 * @param uid
	 * @return Userinfo
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static UserInfo2 GetUserInfo(Integer uid) throws ClientProtocolException, IOException {
		BatchUserRequestDtoBean batchuserrequestdtoBean = new BatchUserRequestDtoBean();
		BatchUserRequestDtoCall batchuserrequestdtoCall = new BatchUserRequestDtoCall();
		List<Integer> userIdList = new ArrayList<>();
		userIdList.add(uid);
		batchuserrequestdtoBean.setUserIdList(userIdList);
		batchuserrequestdtoBean.setreqDomain("www.ymatou.com");
		batchuserrequestdtoCall.setData(batchuserrequestdtoBean);
		batchuserrequestdtoCall.callService();
		return batchuserrequestdtoCall.getResult().get(0);
	}

	/**
	 * 创建用户
	 * 
	 * @param cur
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer createUserCall(CreateUserReq cur) throws ClientProtocolException, IOException {
		CreateUserCall CreateUserCall = new CreateUserCall();
		CreateUserCall.setData(false, cur);
		CreateUserCall.callService();
		Integer uid = CreateUserCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 解绑再绑定手机
	 * 
	 * @param uid
	 * @param oldmobile
	 * @param newmobile
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void resetMobile(Integer uid, String oldmobile, String newmobile) throws ClientProtocolException, IOException {
		UnBindMobileRequestDtoBean UnBindMobileRequestDtoBean = new UnBindMobileRequestDtoBean();
		UnBindMobileRequestDtoCall UnBindMobileRequestDtoCall = new UnBindMobileRequestDtoCall();
		UnBindMobileRequestDtoBean.setMobile(oldmobile);
		UnBindMobileRequestDtoBean.setUserId(uid);
		UnBindMobileRequestDtoCall.setData(UnBindMobileRequestDtoBean);
		UnBindMobileRequestDtoCall.callService();

		BindMobileReq bindMobileBean = new BindMobileReq();
		BindMobileCall bindMobileCall = new BindMobileCall();
		bindMobileBean.setMobile(newmobile);
		bindMobileBean.setUserId(uid);
		bindMobileCall.setData(bindMobileBean);
		bindMobileCall.callService();
	}

	/**
	 * 解绑再绑定邮箱
	 * 
	 * @param uid
	 * @param newmail
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void resetMail(Integer uid, String newmail) throws ClientProtocolException, IOException {
		UnBindMailBean UnBindMailBean = new UnBindMailBean();
		UnBindMailCall UnBindMailCall = new UnBindMailCall();
		UnBindMailBean.setUserId(uid);
		UnBindMailCall.setData(UnBindMailBean);
		UnBindMailCall.callService();

		BindEmailBean BindEmailBean = new BindEmailBean();
		BindEmailCall BindEmailCall = new BindEmailCall();
		BindEmailBean.setEmail(newmail);
		BindEmailBean.setUserId(uid);
		BindEmailCall.setData(BindEmailBean);
		BindEmailCall.callService();
	}

	/**
	 * 初始化第三方注册,默认weixin
	 * 
	 * @return
	 */
	public static CreateThirdPartyUserReq initCreateThirdUserReq() {
		String randomStr = TestDataManager.getRandomNumToHex(6);
		CreateThirdPartyUserReq req = new CreateThirdPartyUserReq();
		req.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
		req.setChannelSource(ChannelSourceEnum.WeiXin);
		req.setThirdPartyId(randomStr);
		req.setAppSource(AppSourceEnum.App);
		req.setClientIp(TestDataManager.getRandomIp());
		req.setUserGender(GenderEnum.Male);
		req.setHeadimgurl("http://img.ymatou.com/" + randomStr);
		req.setOpenId(randomStr);
		req.setCountry("China");
		req.setProvince("SH");
		req.setCity("SH");
		req.setDeviceId(UUID.randomUUID().toString());
		req.setEquimentid(UUID.randomUUID().toString());
		req.setTerminalSource(TerminalSourceEnum.IOS);
		req.setMobile(TestDataManager.getPhoneNum());
		req.setThirdPartyUserName("uname" + randomStr);
		req.setRawThirdPartyName("uname1" + randomStr);
		return req;
	}

	/**
	 * 初始化第三方bind,默认weixin
	 * 
	 * @return
	 */
	public static BindThirdPartyUserReq initBindThirdUserReq(int userId) {

		BindThirdPartyUserReq req = new BindThirdPartyUserReq();

		req.setUserId(userId);
		int randomNum = TestDataManager.getRandomIntNum(9);
		String randomStr = TestDataManager.getRandomNumToHex(6);
		req.setTerminalSource(TerminalSourceEnum.IOS);

		req.setThirdPartyType(ThirdPartyTypeEnum.WeiXin);
		req.setThirdPartyId(randomStr);
		req.setAppSource(AppSourceEnum.App);
		req.setClientIp(TestDataManager.getRandomIp());
		req.setUserGender(GenderEnum.Male);
		req.setHeadimgurl("http://img.ymatou.com/" + randomStr + 1);
		req.setOpenId(randomStr);
		req.setCountry("China");
		req.setProvince("SH");
		req.setCity("SH");
		req.setDeviceId(UUID.randomUUID().toString());
		req.setEquimentid(UUID.randomUUID().toString());
		req.setTerminalSource(TerminalSourceEnum.IOS);
		req.setMobile(TestDataManager.getPhoneNum());

		return req;
	}

	/**
	 * 第三方注册
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer createThirdPartyUserCall(CreateThirdPartyUserReq cur) throws ClientProtocolException, IOException {
		CreateThirdPartyUserCall CreateThirdPartyUserCall = new CreateThirdPartyUserCall();
		CreateThirdPartyUserCall.setData(false, cur);
		CreateThirdPartyUserCall.callService();
		Integer uid = CreateThirdPartyUserCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 更新微信头像
	 * 
	 * @param userid
	 * @param headimg
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void updateWxHeadImg(Integer userid, String headimg) throws ClientProtocolException, IOException {
		UpdateWxHeadImgBean updatewxheadimgBean = new UpdateWxHeadImgBean();
		UpdateWxHeadImgCall updatewxheadimgCall = new UpdateWxHeadImgCall();
		updatewxheadimgBean.setUserId(userid);
		updatewxheadimgBean.setHeadImg(headimg);
		updatewxheadimgCall.setData(updatewxheadimgBean);
		updatewxheadimgCall.callService();
	}

	/**
	 * 第三方绑定
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static Integer bindThirdPartyUserCall(BindThirdPartyUserReq cur) throws ClientProtocolException, IOException {
		BindThirdPartyUserCall BindThirdPartyUserCall = new BindThirdPartyUserCall();
		BindThirdPartyUserCall.setData(false, cur);
		BindThirdPartyUserCall.callService();
		Integer uid = BindThirdPartyUserCall.getJsonObject().get("Result").getAsJsonObject().get("UserId").getAsInt();
		return uid;
	}

	/**
	 * 第三方解绑
	 * 
	 * @param cur
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UnBindThirdPartyUserCall(UnBindThirdPartyUserReq cur) throws ClientProtocolException, IOException {
		UnBindThirdPartyUserCall UnBindThirdPartyUserCall = new UnBindThirdPartyUserCall();
		UnBindThirdPartyUserCall.setData(false, cur);
		UnBindThirdPartyUserCall.callService();
	}

	/**
	 * 锁定用户
	 * 
	 * @param UserId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void lockUsers(Integer userId) throws ClientProtocolException, IOException {
		LockUserRequestDtoBean lockuserrequestdtoBean = new LockUserRequestDtoBean();
		LockUserRequestDtoCall lockuserrequestdtoCall = new LockUserRequestDtoCall();
		lockuserrequestdtoBean.setDescription("自动化锁定");
		lockuserrequestdtoBean.setOperating("autoTest");
		ArrayList userids = new ArrayList<>();
		userids.add(userId);
		lockuserrequestdtoBean.setUserId(userids);
		lockuserrequestdtoCall.setData(false, lockuserrequestdtoBean);
		lockuserrequestdtoCall.callService();
		try {
			if (!Boolean.valueOf(lockuserrequestdtoCall.getJsonObject().get("Success").toString())) {
				Logger.debug("锁定用户失败");
			}
			;
		} catch (Exception e) {
			Logger.debug("锁定用户失败:" + e.getMessage());
		}
	}

	/**
	 * 解除锁定用户
	 * 
	 * @param UserId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static int UnLockUsers(Integer userId) throws ClientProtocolException, IOException {
		LockUserRequestDtoBean lockuserrequestdtoBean = new LockUserRequestDtoBean();
		UnLockUserRequestDtoCall unlockuserrequestdtoCall = new UnLockUserRequestDtoCall();
		lockuserrequestdtoBean.setDescription("自动化锁定");
		lockuserrequestdtoBean.setOperating("autoTest");
		ArrayList userids = new ArrayList<>();
		userids.add(userId);
		lockuserrequestdtoBean.setUserId(userids);
		unlockuserrequestdtoCall.setData(false, lockuserrequestdtoBean);
		unlockuserrequestdtoCall.callService();
		int num = 0;
		try {
			num = unlockuserrequestdtoCall.getJsonObject().get("Result").getAsJsonObject().get("UnlockCount").getAsInt();
		} catch (Exception e) {
			Logger.debug("解锁用户失败:" + e.getMessage());
		}
		return num;
	}

	/**
	 * 认证
	 * 
	 * @param sab
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SignAuthCall signAuth(SignAuthBean sab) throws ClientProtocolException, IOException {
		SignAuthCall sac = new SignAuthCall();
		sac.setData(false, sab);
		sac.callService();
		return sac;
	}

	/**
	 * 解绑手机
	 * 
	 * @param ub
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UnBindMobileCall(UnBindMobileRequestDtoBean ub) throws ClientProtocolException, IOException {
		UnBindMobileRequestDtoCall UnBindMobileRequestDtoCall = new UnBindMobileRequestDtoCall();
		UnBindMobileRequestDtoCall.setData(false, ub);
		UnBindMobileRequestDtoCall.callService();
	}

	/**
	 * 设置头像
	 * 
	 * @param SetUserLogoBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetUserLogoCall(SetUserLogoReq SetUserLogoBean) throws ClientProtocolException, IOException {
		SetUserLogoCall SetUserLogoCall = new SetUserLogoCall();
		SetUserLogoCall.setData(false, SetUserLogoBean);
		SetUserLogoCall.callService();
	}

	/**
	 * 快速设置头像
	 * 
	 * @param userId
	 * @param logoUrl
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetUserLogoCall(Integer userId, String logoUrl) throws ClientProtocolException, IOException {
		SetUserLogoCall SetUserLogoCall = new SetUserLogoCall();
		SetUserLogoReq SetUserLogoBean = new SetUserLogoReq();
		SetUserLogoBean.setUserId(userId);
		SetUserLogoBean.setLogoUrl(logoUrl);
		SetUserLogoBean.setAppId("AutoTest");
		SetUserLogoBean.setClientIp(TestDataManager.getLocalIp());
		SetUserLogoCall.setData(false, SetUserLogoBean);
		SetUserLogoCall.callService();
	}

	/**
	 * 初始化直播微店
	 * 
	 * @return
	 * 
	 */
	public static SellerRegisterBean initSellerReg() {
		SellerRegisterBean srb = new SellerRegisterBean();
		srb.setClientIp(TestDataManager.getRandomIp());
		srb.setDid(TestDataManager.getRandomUUID().toString());
		srb.setLid(TestDataManager.getRandomUUID().toString());
		srb.setLoginId("sr" + YMTDateUtil.getSysTime("MMddHHmmssSSS"));
		srb.setLoginMobile(TestDataManager.getPhoneNum("11"));
		srb.setPassword(JUserCallService.defaultLoginPwd);
		srb.setRegSource(7);
		srb.setTerminalSource(0);
		return srb;
	}

	/**
	 * 直播微店注册
	 * 
	 * @param sellerregisterBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SellerRegisterCall SellerRegisterCall(SellerRegisterBean sellerregisterBean) throws ClientProtocolException, IOException {
		SellerRegisterCall sellerregisterCall = new SellerRegisterCall();
		sellerregisterCall.setData(sellerregisterBean);
		sellerregisterCall.callService();
		return sellerregisterCall;
	}

	/**
	 * 注册接口bean
	 * 
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static UserRegisterInfoRequestDtoBean initUserRegisterInfoRequestDtoBean() throws ClientProtocolException, IOException {
		UserRegisterInfoRequestDtoBean userBean = new UserRegisterInfoRequestDtoBean();
		String loginId = "at" + TestDataManager.randomStr(11);
		if (loginId.toLowerCase().contains("ymt") || loginId.toLowerCase().contains("qq")) {
			loginId = "at" + TestDataManager.randomStr(11);
		}
//		String loginMail = loginId + "@ymatou.com";
		String moblie = TestDataManager.getPhoneNum();
		if (mobileExists(moblie)) {
			moblie = TestDataManager.getPhoneNum();
		}
		String pas = JUserCallService.defaultLoginPwd;
		// 用户类型：0 - 买家，1 - 买手（商家）
		int registerType = 0;
		Boolean isAgreeContract = true;
		int regSource = 0;
		int visitLan = 0;
		ChannelSourceEnum channelSource = ChannelSourceEnum.Alipay;
		UserTerminalSourceEnum terminalSource = UserTerminalSourceEnum.Android;

		String clientIp = TestDataManager.getRandomIp();

		Long tokenTimeOut = (long) 1;

		userBean.setLoginId(loginId);
//		userBean.setLoginMail(loginMail);
		userBean.setLoginMobile(moblie);
		userBean.setPas(pas);
		userBean.setRegisterType(registerType);
		userBean.setIsAgreeContract(isAgreeContract);
		userBean.setRegSource(regSource);
		userBean.setVisitLan(visitLan);
		userBean.setChannelSource(channelSource);
		userBean.setTerminalSource(terminalSource);
		userBean.setClientIp(clientIp);
		userBean.setTokenTimeOut(tokenTimeOut);
		userBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		userBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		return userBean;
	};

	/**
	 * 注册
	 * 
	 * @param urb
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static UserRegisterInfoRequestDtoCall UserRegisterInfoRequestDtoCall(UserRegisterInfoRequestDtoBean urb) throws ClientProtocolException, IOException {
		UserRegisterInfoRequestDtoCall UserRegisterInfoRequestDtoCall = new UserRegisterInfoRequestDtoCall();
		UserRegisterInfoRequestDtoCall.setData(false, urb);
		UserRegisterInfoRequestDtoCall.callService();
		return UserRegisterInfoRequestDtoCall;
	}

	/**
	 * @param UserName
	 * @param pas
	 * @param sourceType
	 * @param ip
	 * @return
	 * @throws InterruptedException
	 */
	public static LoginAuthCall login(String UserName, String pas, String sourceType, String ip, String did) throws InterruptedException {
		LoginAuthBean lab = new LoginAuthBean();
		LoginAuthCall lac = new LoginAuthCall();
		try {
			lab.setLoginId(UserName);
			lab.setPas(pas);
			lab.setSourceType(sourceType);
			lab.setClientIp(ip);
			lab.setDeviceId(did);
			lac.setData(false, lab);
			Logger.comment("用户:" + UserName + "登录");
			lac.callService();
			if (!lac.getSuccess()) {
				Thread.sleep(500);
				lac.callService();
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return lac;
	}

	/**
	 * 初始化阿里账号联合登录Bean
	 * 
	 * 注册需传Mobile 登录需传UserId，且不能传Mobile
	 * 
	 * @param aliUserId
	 * @return
	 */
	public static AliUserRequestDtoBean initAliUserRequestDtoBean() {
		AliUserRequestDtoBean aliuserregbean = new AliUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		aliuserregbean.setSAliUserId(aliUserId);
		aliuserregbean.setSRealName("Lily" + TestDataManager.getRandomNum(10));
		aliuserregbean.setSEmail("12456@123.com");
		aliuserregbean.setRegSource(AppSourceEnum.Wap);
		aliuserregbean.setTerminalSource(TerminalSourceEnum.IOS);
		aliuserregbean.setClientIp(TestDataManager.getRandomIp());
		aliuserregbean.setTokenTimeOut((new Date()).getTime());
		aliuserregbean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);

		return aliuserregbean;
	}

	/**
	 * 阿里账号联合登录
	 * 
	 * @param aliUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static AliUserRequestDtoCall aliUserRequestDto(AliUserRequestDtoBean aliUserRequestDtoBean) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		AliUserRequestDtoCall call = new AliUserRequestDtoCall();
		call.setData(false, aliUserRequestDtoBean);
		call.callService();

		return call;
	}

	/**
	 * 初始化微博注册并登录的Bean
	 * 
	 * 注册需传Mobile 登录需传UserId，且不能传Mobile
	 * 
	 * @return
	 */
	public static SinaWeiBoUserRequestDtoBean initSinaWeiBoUserRequestDtoBean() {
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		regBean.setSWeiboUserId(aliUserId);
		regBean.setSName("regAliUser_" + TestDataManager.getRandomNum(6));
		regBean.setSMail("12456@123.com");
		regBean.setRegSource(AppSourceEnum.App);
		regBean.setTerminalSource(TerminalSourceEnum.IOS);
		regBean.setClientIp(TestDataManager.getRandomIp());
		regBean.setTokenTimeOut((new Date()).getTime());
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setSToken("sToken");

		return regBean;
	}

	/**
	 * 初始化用于微博登录的Bean
	 * 
	 * @return
	 */
	public static SinaWeiBoUserRequestDtoBean initSinaWeiBoUserRequestDtoBeanForRegister() {
		SinaWeiBoUserRequestDtoBean regBean = new SinaWeiBoUserRequestDtoBean();

		String aliUserId = "ali_" + TestDataManager.getRandomNum(10);
		String phone = TestDataManager.getPhoneNum();
		regBean.setSWeiboUserId(aliUserId);
		regBean.setSName("regAliUser_" + TestDataManager.getRandomNum(6));
		regBean.setSMail("12456@123.com");
		regBean.setRegSource(AppSourceEnum.App);
		regBean.setTerminalSource(TerminalSourceEnum.IOS);
		regBean.setClientIp(TestDataManager.getRandomIp());
		regBean.setTokenTimeOut((new Date()).getTime());
		regBean.setMobile(phone);
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setSToken("sToken");

		return regBean;
	}

	/**
	 * 微博联合登录请求
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static SinaWeiBoUserRequestDtoCall sinaWeiBoUserRequestDto(SinaWeiBoUserRequestDtoBean bean) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		SinaWeiBoUserRequestDtoCall call = new SinaWeiBoUserRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;

	}

	public static com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean initWeiXinUserRequestDtoBean() {
		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean regBean = new com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean();

		String wxId = "wx_" + TestDataManager.getRandomNum(10);
		regBean.setUnionId(wxId);
		regBean.setName("regwx_" + TestDataManager.getRandomNum(6));
		regBean.setRegSource(AppSourceEnum.App);

		regBean.setClientIp(TestDataManager.getRandomIp());

		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setTokenSource("tokenSource");
		// regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setCountry("China");
		regBean.setProvince("Shanghai");
		regBean.setCity("City");
		regBean.setHeadimgurl("Headimgurl");
		regBean.setOId("openId_" + TestDataManager.getRandomNum(10));
		regBean.setSex("Femail");
		regBean.setTimeOut(new Date().getTime());
		regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setWeixinToken("weixintoken_" + TestDataManager.getRandomNum(4));

		return regBean;
	}

	public static com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean initWeiXinUserRequestDtoBeanForRegister() {
		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean regBean = new com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean();

		String wxId = "wx_" + TestDataManager.getRandomNum(10);
		String phone = TestDataManager.getPhoneNum();
		regBean.setUnionId(wxId);
		regBean.setName("regwx_" + TestDataManager.getRandomNum(6));
		regBean.setRegSource(AppSourceEnum.App);

		regBean.setClientIp(TestDataManager.getRandomIp());

		regBean.setMobile(phone);
		regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
		regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
		regBean.setTokenSource("tokenSource");
		// regBean.setTSource(TerminalSourceEnum.PC);
		regBean.setCountry("Country");
		regBean.setProvince("Province");
		regBean.setCity("City");
		regBean.setHeadimgurl("Headimgurl");
		regBean.setOId("openId_" + TestDataManager.getRandomNum(10));

		return regBean;
	}

	/**
	 * 微信联合认证
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static WeiXinUserRequestDtoCall weiXinUserRequestDto(com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean bean) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		WeiXinUserRequestDtoCall call = new WeiXinUserRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;
	}

	/**
	 * 初始化绑定阿里账号Bean
	 * 
	 * @param token
	 * @return
	 */
	public static BindAliUserRequestDtoBean initBindAliUserRequestDtoBean(String token) {
		BindAliUserRequestDtoBean bindAliUserRequestDtoBean = new BindAliUserRequestDtoBean();

		String ali = "NewBindAli_" + TestDataManager.getRandomNum(10);

		bindAliUserRequestDtoBean.setToken(token);
		bindAliUserRequestDtoBean.setClientType("mainsite");

		AliUserRequestDtoBean aliUserRequestDtoBean = initAliUserRequestDtoBean();
		aliUserRequestDtoBean.setSAliUserId(ali);
		bindAliUserRequestDtoBean.setAliUser(aliUserRequestDtoBean);

		return bindAliUserRequestDtoBean;
	}

	/**
	 * 绑定阿里账号
	 * 
	 * @param bindAliUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static BindAliUserRequestDtoCall BindAliUserRequestDto(BindAliUserRequestDtoBean bindAliUserRequestDtoBean) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		BindAliUserRequestDtoCall BindAliUserRequestDtoCall = new BindAliUserRequestDtoCall();
		BindAliUserRequestDtoCall.setData(false, bindAliUserRequestDtoBean);
		BindAliUserRequestDtoCall.callService();

		return BindAliUserRequestDtoCall;
	}

	public static BindSinaWeiboUserRequestDtoBean initBindSinaWeiboUserRequestDtoBean(String token) throws InterruptedException {
		Thread.sleep(500);
		BindSinaWeiboUserRequestDtoBean bindsinaweibouserrequestdtoBean = new BindSinaWeiboUserRequestDtoBean();

		String weiboUserId = "NewBindWeibo_" + TestDataManager.getRandomNum(10);
		bindsinaweibouserrequestdtoBean.setToken(token);
		bindsinaweibouserrequestdtoBean.setClientType("mainsite");

		SinaWeiBoUserRequestDtoBean sinaWeiBoUserRequestDtoBean = initSinaWeiBoUserRequestDtoBean();
		sinaWeiBoUserRequestDtoBean.setSWeiboUserId(weiboUserId);

		bindsinaweibouserrequestdtoBean.setWeiBoUser(sinaWeiBoUserRequestDtoBean);

		return bindsinaweibouserrequestdtoBean;
	}

	/**
	 * 新浪微博联合登陆
	 * 
	 * @param bindSinaWeiboUserRequestDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static BindSinaWeiboUserRequestDtoCall bindSinaWeiboUserRequestDto(BindSinaWeiboUserRequestDtoBean bindSinaWeiboUserRequestDtoBean)
			throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		BindSinaWeiboUserRequestDtoCall call = new BindSinaWeiboUserRequestDtoCall();
		call.setData(false, bindSinaWeiboUserRequestDtoBean);
		call.callService();

		return call;
	}

	/**
	 * 设置绑定微信默认bean
	 * 
	 * @param token
	 * @return
	 * @throws InterruptedException 
	 */
	public static BindWeiXinUseroRequestDtoBean initBindWeiXinUseroRequestDtoBean(String token) throws InterruptedException {
		Thread.sleep(200);
		BindWeiXinUseroRequestDtoBean bindweixinuserorequestdtoBean = new BindWeiXinUseroRequestDtoBean();

		bindweixinuserorequestdtoBean.setToken(token);
		bindweixinuserorequestdtoBean.setClientType("mainsite");

		com.ymatou.iapi.login.parameter.WeiXinUserRequestDtoBean weiXinUserRequestDtoBean = initWeiXinUserRequestDtoBean();
		bindweixinuserorequestdtoBean.setWeiXinUser(weiXinUserRequestDtoBean);

		return bindweixinuserorequestdtoBean;
	}

	/**
	 * 绑定微信
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 */
	public static BindWeiXinUseroRequestDtoCall bindWeiXinUseroRequestDto(BindWeiXinUseroRequestDtoBean bean) throws ClientProtocolException, IOException, InterruptedException {
		Thread.sleep(500);
		BindWeiXinUseroRequestDtoCall call = new BindWeiXinUseroRequestDtoCall();
		call.setData(false, bean);
		call.callService();

		return call;
	}

	/**
	 * 用户服务设置身份证信息
	 * 
	 * @param bean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SetIdcardCall SetIdcardCall(SetIdcardBean bean) throws ClientProtocolException, IOException {
		SetIdcardCall call = new SetIdcardCall();
		call.setData(false, bean);
		call.callService();

		return call;
	}

	/**
	 * 初始化默认用户身份信息
	 * 
	 * @param uid
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static SetIdcardBean initSetIdcardBean(Integer uid) throws ClientProtocolException, IOException {
		SetIdcardBean setidcardBean = new SetIdcardBean();
		setidcardBean.setUserId(uid);
		setidcardBean.setIdCardName(TestDataManager.getChineseName());
		setidcardBean.setIdCardNum(TestDataManager.getCardId(18, 10));
		return setidcardBean;
	}

	/**
	 * 设置解绑第三方账号默认Bean
	 * 
	 * @param thirdPartyId
	 * @param thirdPartyType:Enum
	 *            ThirdPartyType
	 * @param userId
	 * @return
	 */
	public static UnBindThirdPartyAccountDtoBean initUnBindThirdPartyAccountDtoBean(String thirdPartyId, String thirdPartyType, Integer userId) {
		UnBindThirdPartyAccountDtoBean unbindthirdpartyaccountdtoBean = new UnBindThirdPartyAccountDtoBean();

		unbindthirdpartyaccountdtoBean.setThirdPartyId(thirdPartyId);
		unbindthirdpartyaccountdtoBean.setThirdPartyType(thirdPartyType);
		unbindthirdpartyaccountdtoBean.setUserId(userId);
		return unbindthirdpartyaccountdtoBean;
	}

	/**
	 * 解绑第三方账号
	 * 
	 * @param unBindThirdPartyAccountDtoBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static UnBindThirdPartyAccountDtoCall unBindThirdPartyAccountDto(UnBindThirdPartyAccountDtoBean unBindThirdPartyAccountDtoBean)
			throws ClientProtocolException, IOException {
		UnBindThirdPartyAccountDtoCall unBindThirdPartyAccountDtoCall = new UnBindThirdPartyAccountDtoCall();
		unBindThirdPartyAccountDtoCall.setData(false, unBindThirdPartyAccountDtoBean);
		unBindThirdPartyAccountDtoCall.callService();

		return unBindThirdPartyAccountDtoCall;
	}

	public static Boolean mobileExists(String mobile) throws ClientProtocolException, IOException {
		MobileexistsBean mobileexistsBean = new MobileexistsBean();
		MobileexistsCall mobileexistsCall = new MobileexistsCall();
		mobileexistsBean.setMobile(mobile);
		mobileexistsCall.setData(false, mobileexistsBean);
		mobileexistsCall.callService();
		return Boolean.valueOf(mobileexistsCall.getResultData().getResult().getExists());
	}

	/**
	 * 第三方用户登入 注册需传mobile
	 * 
	 * @return
	 */
	public static ThirdpartyLoginBean initLoginBean() {
		ThirdpartyLoginBean loginBean = new ThirdpartyLoginBean();

		loginBean.setThirdPartyType(ThirdPartyTypeEnum.QQ);
		loginBean.setThirdPartyId("QQ_" + TestDataManager.getRandomNum(10));
		loginBean.setThirdPartyUserName("小鱼儿_" + TestDataManager.getRandomNum(10));
		loginBean.setMail("tony@ymatou.com");
		loginBean.setAppSource(AppSourceEnum.App);
		loginBean.setTerminalSource(TerminalSourceEnum.Android);
		loginBean.setClientIp(TestDataManager.getRandomIp());
		loginBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		loginBean.setDid(TestDataManager.getRandomUUID().toString());

		return loginBean;
	}

	/**
	 * 用户登入bean
	 * 
	 * @param regbean
	 * @return
	 */
	public static LoginAuthBean initLoginAuthBean(UserRegisterInfoRequestDtoBean regbean) {
		LoginAuthBean lab = new LoginAuthBean();
		lab.setLoginId(regbean.getLoginId());
		lab.setPas(regbean.getPas());
		lab.setSourceType("app");
		lab.setClientIp(regbean.getClientIp());
		lab.setTSource("ios");
		lab.setTokenSource("app");
		lab.setDeviceId(regbean.getDeviceId());
		return lab;
	}

	/**
	 * 用户登入
	 * 
	 * @param loginBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static LoginAuthCall loginAuth(LoginAuthBean loginBean) throws ClientProtocolException, IOException {
		LoginAuthCall loginCall = new LoginAuthCall();
		loginCall.setData(false, loginBean);
		loginCall.callService();
		return loginCall;
	}

	/**
	 * 第三方用户登入
	 * 
	 * @param loginBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static ThirdpartyLoginCall login(ThirdpartyLoginBean loginBean) throws ClientProtocolException, IOException {
		ThirdpartyLoginCall loginCall = new ThirdpartyLoginCall();

		loginCall.setData(false, loginBean);
		loginCall.callService();

		return loginCall;
	}

	public static BindBean initBindBean(String token) {
		BindBean bindBean = new BindBean();

		bindBean.setToken(token);
		bindBean.setClientType("mainsite");
		bindBean.setThirdPartyType(ThirdPartyTypeEnum.QQ);
		bindBean.setThirdPartyId("Login_" + TestDataManager.getRandomNum(10));
		bindBean.setThirdPartyUserName("小鱼儿");
		bindBean.setMail("tony@ymatou.com");
		bindBean.setAppSource(AppSourceEnum.App);
		bindBean.setTerminalSource(TerminalSourceEnum.Android);
		bindBean.setClientIp(TestDataManager.getRandomIp());
		bindBean.setDeviceId(TestDataManager.getRandomUUID().toString());
		bindBean.setDid(TestDataManager.getRandomUUID().toString());

		return bindBean;
	}

	public static ThirdpartyLoginBean getLoginBean(BindBean bindBean) {
		ThirdpartyLoginBean loginBean = new ThirdpartyLoginBean();

		loginBean.setThirdPartyType(bindBean.getThirdPartyType());
		loginBean.setThirdPartyId(bindBean.getThirdPartyId());
		loginBean.setThirdPartyUserName(bindBean.getThirdPartyUserName());
		loginBean.setMail(bindBean.getMail());
		loginBean.setAppSource(bindBean.getAppSource());
		loginBean.setTerminalSource(bindBean.getTerminalSource());
		loginBean.setClientIp(bindBean.getClientIp());
		loginBean.setDeviceId(bindBean.getDeviceId());
		loginBean.setDid(bindBean.getDid());

		return loginBean;
	}

	public static BindCall Bind(BindBean bindBean) throws ClientProtocolException, IOException, InterruptedException {
		// 绑定要用到token 会出现token没有同步到mongo从库导致case失败
		Thread.sleep(500);
		BindCall call = new BindCall();

		call.setData(false, bindBean);
		call.callService();

		return call;
	}

	/**
	 * 初始化数据库配置 无用 废弃
	 * 
	 * @throws InterruptedException
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	@Deprecated
	public static void initUserSafeConfig() throws InterruptedException, ClientProtocolException, IOException {
		UserSafeWapper authWapper = new UserSafeWapper();
		// 买家用户总开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "Safe", "Open", "1");
		// 买家Token90天开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "Token", "Open", "1");
		// ?开启设备
		authWapper.updateNewLoginSafeConfiguration("Buyer", "Device", "Open", "1");
		// 买家设备号黑名单开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "DeviceBlacklist", "Open", "1");
		// 买家密码登入开关
		authWapper.updateNewLoginSafeConfiguration("Buyer", "LoginPas", "Open", "1");
		// 买家设备号常用IP区域
		authWapper.updateNewLoginSafeConfiguration("Buyer", "IpOften", "Open", "1");
		// 买家是否开启常用设备
		authWapper.updateNewLoginSafeConfiguration("Buyer", "OftenDevice", "Open", "1");
		// 商家用户总开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Safe", "Open", "1");
		// 商家用户密码登入次数开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "LoginPas", "Open", "1");
		// 商家用户IP黑名单登入次数开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "IpBlacklist", "Open", "1");
		// 商家用户IP区域开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "IpOften", "Open", "1");
		// 商家用户Token90天开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Token", "Open", "1");
		// 商家用户设备号开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Device", "Open", "1");
		// 商家用户设备号黑名单开关
		authWapper.updateNewLoginSafeConfiguration("Seller", "Deviceblacklist", "Open", "1");
	}

	/**
	 * 更新交易密码
	 * 
	 * @param mobile
	 * @param uid
	 * @param newpasswd
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateTradingPwd(int uid, String newpasswd) throws ClientProtocolException, IOException {
		UpdateTradingPwdBean updadetradingpwdbean = new UpdateTradingPwdBean();
		UpdateTradingPwdCall updatetradingpwdcall = new UpdateTradingPwdCall();
		updadetradingpwdbean.setAType("ByUserId");
		// updadetradingpwdbean.setLoginMobile(mobile);
		updadetradingpwdbean.setNewPassword(newpasswd);
		updadetradingpwdbean.setOldPassword(null);
		updadetradingpwdbean.setPasActionType("ModifyTradingPassword");
		updadetradingpwdbean.setUserId(uid);
		updatetradingpwdcall.setData(false, updadetradingpwdbean);
		updatetradingpwdcall.callService();
	}

	/**
	 * 更新登入密码
	 * 
	 * @param uid
	 * @param newpasswd
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void UpdateLoginPwd(int uid, String newpasswd) throws ClientProtocolException, IOException {
		PasswordResetRequestDtoBean passwordresetrequestdtoBean = new PasswordResetRequestDtoBean();
		PasswordResetRequestDtoCall passwordresetrequestdtoCall = new PasswordResetRequestDtoCall();
		passwordresetrequestdtoBean.setUserId(uid);
		passwordresetrequestdtoBean.setNewPassword(newpasswd);
		passwordresetrequestdtoCall.setData(false, passwordresetrequestdtoBean);
		passwordresetrequestdtoCall.callService();
	}

	/**
	 * 修改昵称
	 * 
	 * @param uid
	 * @param nickName
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetNickName(int uid, String nickName) throws ClientProtocolException, IOException {
		SetNickNameDtoBean setnicknamedtoBean = new SetNickNameDtoBean();
		SetNickNameDtoCall setnicknamedtoCall = new SetNickNameDtoCall();
		setnicknamedtoBean.setUserId(uid);
		setnicknamedtoBean.setNickName(nickName);
		setnicknamedtoCall.setData(false, setnicknamedtoBean);
		setnicknamedtoCall.callService();
	}

	/**
	 * 绑定邮件
	 * 
	 * @param uid
	 * @param email
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void BindEmail(Integer uid, String email) throws ClientProtocolException, IOException {
		BindEmailBean BindEmailBean = new BindEmailBean();
		BindEmailCall BindEmailCall = new BindEmailCall();
		BindEmailBean.setEmail(email);
		BindEmailBean.setUserId(uid);
		BindEmailCall.setData(false, BindEmailBean);
		BindEmailCall.callService();
	}

	/**
	 * 初始化地址bean 默认添加 setAction可以设置为 "Add" "Update" "SetDefault" "MarkDelete";
	 * 
	 * @param uid
	 * @return
	 */
	public static AddressRequestDtoBean initAddressBean(int uid) {
		AddressRequestDtoBean address = new AddressRequestDtoBean();
		address.setiAddressId(1);
		address.setiUserid(uid);
		address.setsAddressCode("100101");
		address.setsBaseAddress(TestDataManager.getRandomNum(5) + ":autotest:" + uid);
		address.setsDetailAddress(TestDataManager.getRandomNum(5) + ":autotest:" + uid);
		address.setiAction(0);
		address.setsPostCode("100100");
		address.setsTelphone("100100");
		address.setsMobilePhone(TestDataManager.getPhoneNum());
		address.setsRecipient("autotest");
		address.setsEmail("autotest@ymatou.com");
		address.setbIsDefault(false);
		address.setbXloboChecked(false);
		address.setAction("Add");
		return address;
	}

	/**
	 * 返回Result addressid
	 * 
	 * @param addressBean
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws JSONException
	 */
	public static String AddressRequestDtoCall(AddressRequestDtoBean addressBean) throws ClientProtocolException, IOException, JSONException {
		Logger.comment(addressBean.getiUserid() + ":操作地址服务:" + addressBean.getAction());
		AddressRequestDtoCall gac = new AddressRequestDtoCall();
		gac.setData(false, addressBean);
		gac.callService();
		return gac.getString("Result");
	}

	public static List<AddressResp> getAddressInfoList(int uid) throws ClientProtocolException, IOException, JSONException {

		AddressRequestDtoBean arb = new AddressRequestDtoBean();
		arb.setiUserid(uid);
		GAddressRequestDtoCall gac = new GAddressRequestDtoCall();
		gac.setData(false, arb);
		gac.callService();
		return gac.getAddressList();

		/*
		 * UserRequestDtoBean userrequestdtoBean = new UserRequestDtoBean();
		 * UserRequestDtoCall userrequestdtoCall = new UserRequestDtoCall();
		 * userrequestdtoBean.setIUserId(uid);
		 * 
		 * userrequestdtoCall.setData(FormatUtil.beanToHttpString(
		 * userrequestdtoBean, true, false)); userrequestdtoCall.callService();
		 * 
		 * return userrequestdtoCall.getResult();
		 */

	}

	/**
	 * 设置个人简介
	 * 
	 * @param uid
	 * @param remark
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SetRemark(Integer uid, String remark) throws ClientProtocolException, IOException {
		SetRemarkBean setremarkBean = new SetRemarkBean();
		SetRemarkCall setremarkCall = new SetRemarkCall();
		setremarkBean.setRemark(remark);
		setremarkBean.setUserId(uid);
		setremarkCall.setData(false, setremarkBean);
		setremarkCall.callService();
	}

	/**
	 * 修改用户等级
	 * 
	 * @param uid
	 * @param level
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void ExpChange(Integer uid, Integer level) throws ClientProtocolException, IOException {
		ExpChangeBean ExpChangeBean = new ExpChangeBean();
		ExpChangeCall ExpChangeCall = new ExpChangeCall();
		ExpChangeBean.setExp(1);
		ExpChangeBean.setUserId(uid);
		ExpChangeBean.setLevel(level);
		ExpChangeCall.setData(false, ExpChangeBean);
		ExpChangeCall.callService();
	}

	/**
	 * 获取rsa加密后的pwd
	 * 
	 * @param npwd
	 * @return
	 * @throws Exception
	 */
	public static String getRsaPwd(String npwd) throws Exception {
		byte[] rsabytes = RSAUtils.encryptByPublicKey(npwd.getBytes(), (RSAPublicKey) RSAUtils.loadPublicKey(EnvSetup.getData("USER_PUBLIC_KEY")));
		String rsanpwd = Base64.getEncoder().encodeToString(rsabytes);
		return rsanpwd;
	}

	/**
	 * 获取des加密后的pwd
	 * 
	 * @param npwd
	 * @return
	 * @throws Exception
	 */
	public static String getDesPwd(String npwd) throws Exception {
		String pwd = DesUtil.encrypt(npwd, DesUtil.DES_KEY_STRING, DesUtil.DES_IVPARAMETER);
		return pwd;
	}

	/**
	 * 直播微店
	 * 
	 * @return
	 */
	public static WxUserLoginBean initWxuserloginBean() {
		WxUserLoginBean wx = new WxUserLoginBean();
		wx.setAppSource(20);
		wx.setCity("Shanghai");
		wx.setClientIp(TestDataManager.getRandomIp());
		wx.setCountry("China");
		wx.setDeviceId(TestDataManager.getRandomUUID().toString());
		wx.setDid(TestDataManager.getRandomUUID().toString());
		wx.setHeadImgUrl("http://img.ymatou.com/app/flag/circle/France.png");
		wx.setNickName("nk" + YMTDateUtil.getSysTime("MMddHHmmssSSS"));
		wx.setOpenId(TestDataManager.getRandomUUID().toString().replaceAll("-", "").substring(0, 30));
		wx.setProvince("Shanghai");
		wx.setTerminalSource(2);
		wx.setUnionId(TestDataManager.getRandomUUID().toString().replaceAll("-", "").substring(0, 30));
		return wx;
	}

	/**
	 * 直播微店
	 * 
	 * @param wxuserloginBean
	 * @return
	 * @throws IOException
	 * @throws ClientProtocolException
	 */
	public static WxUserLoginCall WxUserLoginCall(WxUserLoginBean wxuserloginBean) throws ClientProtocolException, IOException {
		WxUserLoginCall wxuserloginCall = new WxUserLoginCall();
		wxuserloginCall.setData(wxuserloginBean);
		wxuserloginCall.callService();
		return wxuserloginCall;
	}

	public static void main(String args[]) throws Exception {
//		2019-12-04 17:00:49,428 [http-nio-9200-exec-1] ERROR c.y.d.domain.utils.SensitiveDataUtil KEY[GetUserListReq|5de775c15254a80015a650e1] [c970cf48cd34403d] - 敏感数据解密异常, key:_ymt2018_, encryptedText:D38C9F0FA84B5E6D0281B3262DD00D13
		// Logger.debug(TestDataManager.getCardId(20, 1));
	}

	public static void setOnlineStatusOp(Integer userId, String OpType, String op) throws ClientProtocolException, IOException, InterruptedException {
		OnlinestatusOpBean onlinestatusopBean=new  OnlinestatusOpBean();
		OnlinestatusOpCall onlinestatusopCall=new OnlinestatusOpCall();
		onlinestatusopBean.setOpType(OpType);
		onlinestatusopBean.setOp(op);
		onlinestatusopBean.setUserId(userId);
		onlinestatusopBean.setOpTime(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"));
		onlinestatusopBean.setAppSource("autotest");
		onlinestatusopCall.setData(onlinestatusopBean);
		onlinestatusopCall.callService();
		Thread.sleep(1000);
	}
	public static void setOnlineStatusOp(Integer userId, String OpType, String op,String optime) throws ClientProtocolException, IOException {
		OnlinestatusOpBean onlinestatusopBean=new  OnlinestatusOpBean();
		OnlinestatusOpCall onlinestatusopCall=new OnlinestatusOpCall();
		onlinestatusopBean.setOpType(OpType);
		onlinestatusopBean.setOp(op);
		onlinestatusopBean.setUserId(userId);
		onlinestatusopBean.setOpTime(optime);
		onlinestatusopBean.setAppSource("autotest");
		onlinestatusopCall.setData(onlinestatusopBean);
		onlinestatusopCall.callService();
	}
}
